<template>
  <v-layout type="main">
    <div class="alike-lis-header">
      <div class="lis-header-left">
        <div class="search-box">
          <el-input prefix-icon="el-icon-search" v-model="Pagedata.name" class="search" placeholder="" @input="getData" />
        </div>
      </div>
    </div>

    <el-table :data="tableData">
      <el-table-column prop="name" label="名称" />
      <!-- <el-table-column prop="model" label="GPU型号">、
        <template slot-scope="{ row }">
          <el-button type="text" @click="openSetGPU(row)">设置</el-button>
        </template>
      </el-table-column> -->
      <el-table-column prop="addresses[0].address" label="IP地址" />

    </el-table>

    <el-dialog title="设置节点GPU型号" :visible.sync="showSet">
      <div class="add-user-box">
        <el-select v-model="addForm.model" placeholder="选择GPU型号" class="user-lis">
          <el-option v-for="(e, i) in allGpus" :key="i" :label="e.model" :value="e.model" />
        </el-select>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="setNodeGpu">确定</el-button>
        <el-button class="none-type" @click="showSet = false">关 闭</el-button>
      </span>
    </el-dialog>
  </v-layout>
</template>

<script>
import { getAllGpuModel } from '@/api/gpu'
import { getNodelAll, setNodeGpuModel, delGpuModel } from '@/api/edge'
import { formatTime } from '@/utils/tool'

export default {
  data() {
    return {
      tableData: [],
      addForm: {},
      showSet: false,
      Pagedata: {
        current: 1,
        size: 10,
        total: 0,
      },
      allGpus: [],
    };
  },
  async created() {
    this.getData()
    this.getGpus()
  },
  destroyed() {

  },
  methods: {
    async getData() {
      let res = await getNodelAll()
      console.log("=======================" + res.data)
      this.tableData = res.data
      this.Pagedata.total = res.total
    },
    formatterTime({ createTime }) {
      return formatTime(createTime)
    },
    async setNodeGpu() {
      if (this.addForm.model == '无') {
        await delGpuModel(this.addForm.nodeName)
      } else {
        await setNodeGpuModel(this.addForm.nodeName, this.addForm.model)
      }
      this.showSet = false
      this.getData()
    },
    async getGpus() {
      let ret = await getAllGpuModel()
      this.allGpus = ret.data
      this.allGpus.push({ model: '无' })
    },
    async del({ id }) {
      await delGpuModel({ id })
      this.getData()
    },
    openSetGPU(node) {
      console.log('node', node)
      this.addForm = { nodeName: node.name }
      this.showSet = true
    }
  }
}
</script>
<style lang="less" scoped></style>